package day11.byteStream;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author Xiao
 * @date 2021/8/1
 */
public class OutputDemo04 {
    /**
     * 字节流写数据同时处理异常的重要步骤
     *      1.将创建字节流对象和写出数据的代码放在try中
     *      2.在catch中捕获IOException异常
     *      3.在finally中进行释放资源
     */
    public static void main(String[] args) {
        FileOutputStream fos = null;
        try {
//            System.out.println(2/0);
            fos = new FileOutputStream("E:\\develop\\Test\\a01.txt");
            fos.write("abc".getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
